package com.ziyucoding.springboot.labs.lab3.sca.rocketmqdemo.dtd.order.controller;

import com.ziyucoding.springboot.labs.lab3.sca.rocketmqdemo.dtd.order.dto.OrderDTO;
import com.ziyucoding.springboot.labs.lab3.sca.rocketmqdemo.dtd.order.service.OrderService;
import org.apache.rocketmq.client.exception.MQClientException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单控制器
 *
 * @author ziyucoding
 * @date 2023-04-02
 **/
@RestController
@RequestMapping("/order")
public class OrderController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private OrderService orderService;

    @PostMapping("/create")
    public void createOrder(@RequestBody OrderDTO order) throws MQClientException {
        logger.info("接收到订单数据：{}", order.getCommodityCode());
        orderService.createOrder(order);
    }
}
